#!/usr/bin/python3
# baixar antes as ferramenta ffmpeg -> sudo apt-get install ffmpeg
import youtube_dl, sys
try:
	link = input("cole o link aqui:")
	#link = sys.argv[1]
	print("########################################")
	print(" 	YOUTUBE_DL PYTHON3 ")
	print("########################################")

	print("\nEscolha uma Formato de video")
	print("1) youtube.com [ FORMATO ORIGINAL ] ")
	print("2) youtube.com [ 640x360 ]")
	print("3) vimeo.com [ FORMATO ORIGINAL ]")
	print("4) xV1d305.com [ FORMATO ORIGINAL ]")
	print("5) site/animes [ FORMATO ORIGINAL ]")
	print("6) mp3 [ MUSICA APENAS ]")
	print("7) [ Sair do Menu ] ")
	escolha = str(input("-> "))


	if escolha == "1" or escolha == "3" or escolha == "4" or escolha == "5":
		print("\nVideo Original [youtube.com , vimeo.com, xV1d305.com, site/animes]")
		ydl_opts = {
				#'format' : 'mp4',
				#'format' : '18/mp4',
				#'format' : 'best/best',
				'noplaylist' : True}

		with youtube_dl.YoutubeDL(ydl_opts) as ydl:
		    ydl.download(['%s' %link])

	elif escolha =="2":
		print("\n640x360 mobile [so funciona com youtube.com] ")
		ydl_opts = {
				#'format' : 'mp4',
				'format' : '18/mp4',
				#'format' : 'best/best',
				'noplaylist' : True}
		
		with youtube_dl.YoutubeDL(ydl_opts) as ydl:
		    ydl.download(['%s' %link])



	elif escolha =="6":
		print("\nmp3 mobile")
		print("pode demorar um pouco..")
		ydl_opts = {
		       'format': 'bestaudio/best',
		       #'outtmpl': outtmpl,
			'noplaylist' : True,
		       'postprocessors': [{
			   'key': 'FFmpegExtractAudio',
			   'preferredcodec': 'mp3',
			   'preferredquality': '192',
		       },
			   {'key': 'FFmpegMetadata'},
		       ],
		       }
		with youtube_dl.YoutubeDL(ydl_opts) as ydl:
		    ydl.download(['%s' %link])

	elif escolha == "7":
		print("Saindo..")
	else:
		print("escolha errada!!")
except:
	print("Deu erro!")
